package com.tsingteng.cosfun.ui.cosfun.presenter;

import android.util.Log;

import com.tsingteng.cosfun.bean.BaseBackBean;
import com.tsingteng.cosfun.bean.BaseDataBean;
import com.tsingteng.cosfun.bean.CommBean;
import com.tsingteng.cosfun.bean.PullBlackBean;
import com.tsingteng.cosfun.callback.RxObserver;
import com.tsingteng.cosfun.mvp.presenter.BasePresenter;
import com.tsingteng.cosfun.ui.cosfun.contract.CommContract;
import com.tsingteng.cosfun.ui.cosfun.contract.ZanContract;
import com.tsingteng.cosfun.ui.cosfun.imodel.CommModel;
import com.tsingteng.cosfun.ui.cosfun.imodel.ZanModel;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class CommPresenter implements CommContract.ICommPresenter {
    CommModel commModel = null;
    CommContract.ICommView iCommView = null;

    public CommPresenter(CommContract.ICommView iCommView) {
        this.commModel = new CommModel();
        this.iCommView = iCommView;
    }

    @Override
    public void getOpusComm(int isTop,String workId, String c, String deviceId, String parentCommentId, String userId, String commentMsg) {
        commModel.getOpusComm(isTop,workId, c, deviceId, parentCommentId, userId, commentMsg, new Callback<BaseBackBean>() {
            @Override
            public void onResponse(Call<BaseBackBean> call, Response<BaseBackBean> response) {
                iCommView.successStatus(response.body());
            }

            @Override
            public void onFailure(Call<BaseBackBean> call, Throwable t) {
                iCommView.failure(0, t.getMessage());
            }
        });
    }

    @Override
    public void getOpusCommList(String userId, String c, String workId, String page_no, String page_size, String deviceId) {
        commModel.getOpusCommList(userId, c, workId, page_no, page_size, deviceId, new Callback<BaseDataBean<CommBean>>() {
            @Override
            public void onResponse(Call<BaseDataBean<CommBean>> call, Response<BaseDataBean<CommBean>> response) {
                Log.e("test", "response.body().getStatus()=" + response.body().getStatus());
                if (response.body().getStatus() == 200) {
                    iCommView.succeed(response.body().data);
                } else {
                    iCommView.failure(response.body().getStatus(), response.body().getMsg());
                }
            }

            @Override
            public void onFailure(Call<BaseDataBean<CommBean>> call, Throwable t) {
                iCommView.failure(0, t.getMessage());
            }
        });
    }
    @Override
    public void getCancelPullBlack(long user_id) {
        Callback<PullBlackBean> workCallback = new Callback<PullBlackBean>() {
            @Override
            public void onResponse(Call<PullBlackBean> call, Response<PullBlackBean> response) {
                PullBlackBean body = response.body();
                int data = body.getData();
                iCommView.showCancelPullBlack(data);
            }

            @Override
            public void onFailure(Call<PullBlackBean> call, Throwable t) {
                Log.e("/////", t.getMessage());
            }
        };
        commModel.getCancelPullBlackInfo(user_id, workCallback);
    }

    @Override
    public void getCommlike(String workId, String userId, String commId, String type) {
        commModel.getOpusCommLike(workId, userId, commId, type, new Callback<BaseDataBean<String>>() {
            @Override
            public void onResponse(Call<BaseDataBean<String>> call, Response<BaseDataBean<String>> response) {

            }

            @Override
            public void onFailure(Call<BaseDataBean<String>> call, Throwable t) {

            }
        });
    }


    @Override
    public void commDel(String commid) {
        commModel.commDel(commid, new Callback<BaseDataBean<String>>() {
            @Override
            public void onResponse(Call<BaseDataBean<String>> call, Response<BaseDataBean<String>> response) {

            }

            @Override
            public void onFailure(Call<BaseDataBean<String>> call, Throwable t) {

            }
        });
    }
}
